<template>
  <div class="container">
    <el-table :data="tableParams.rows">
      <el-table-column type="index" width="50" />
      <el-table-column prop="declarationBatchNumber" label="批次号" width="170" />
      <el-table-column prop="address" label="姓名">
        <template #default="scope">
          {{field_format(scope.row,'name')}}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="身份证" width="170">
        <template #default="scope">
          {{field_format(scope.row,'identityCard')}}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="学历" width="200" show-overflow-tooltip>
        <template #default="scope">
          {{field_format(scope.row,'education')}}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="毕业院校" width="200" show-overflow-tooltip>
        <template #default="scope">
          {{field_format(scope.row,'school')}}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="毕业专业" width="200" show-overflow-tooltip>
        <template #default="scope">
          {{field_format(scope.row,'graduationMajor')}}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="工作年限" width="150" show-overflow-tooltip>
        <template #default="scope">
          {{field_format(scope.row,'workYears')}}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="学历证书编号" width="170" show-overflow-tooltip />
      <el-table-column prop="address" label="等级证书编号" width="170" show-overflow-tooltip />
      <el-table-column prop="address" label="是否需要纸质证书" width="170" show-overflow-tooltip />
    </el-table>
  </div>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
const instance = getCurrentInstance();
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
let props = defineProps(["info", "type"]);

let loading = ref(false);
let formInline = ref({
  pageIndex: 1,
  pageSize: 150,
});
let tableParams = ref({});
let templateUrl;

function field_format(item, key) {
  let row = item.source ? item.user_data : item.user_Info.baseInfo;
  return row[key];
}

async function getInfo() {
  try {
    loading.value = true;
    if (!props.info._id) return;
    formInline.value.classId = props.info._id;
    tableParams.value = await proxy.$apis.classStudent({
      type: "list",
      data: formInline.value,
    });
    console.log("tableParams.value", tableParams.value);
  } catch (error) {
  } finally {
    loading.value = false;
  }
}

async function exportWord() {
  let resp = await counter.studentRosterExportParams(props.info._id);
  let ret = await proxy.$apis.classDocExport({
    templateURL: templateUrl,
    data: resp,
    fileName: "学员花名册.docx",
  });
  window.location.href = ret;
}

async function getTemplateUrl() {
  try {
    templateUrl = await proxy.$apis.fileTemplate({
      data: { type: props.type },
      type: "downLoad",
    });
  } catch (error) {}
}

function downLoadTemplate() {
  window.location.href = templateUrl;
}

watch(
  () => [props.info, props.type],
  (newValue, oldValue) => {
    if (newValue) {
      getInfo();
      getTemplateUrl();
    }
  },
  { immediate: true, deep: true }
);

defineExpose({ exportWord, downLoadTemplate, getTemplateUrl });
</script>



<style lang="scss" scoped>
.container {
}
</style>








